package com.example.weatherforecast.net

import android.content.Context
import com.android.volley.RequestQueue
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley

class MyVolleyQueue constructor(context: Context) {

    val requestQueue: RequestQueue by lazy {
        Volley.newRequestQueue(context.applicationContext)
    }

    companion object {
        @Volatile
        var INSTANCE : MyVolleyQueue  ?= null
        fun getMyVolleyQueueInstance(context: Context): MyVolleyQueue? {
            INSTANCE ?: synchronized(this) {
                INSTANCE ?: MyVolleyQueue(context).also {
                    INSTANCE = it
                }
            }

            return INSTANCE
        }
    }

    fun addRequest(request : StringRequest) {
        requestQueue.add(request)
    }

}